home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
lang_c
/
msqc25t1
/
appmenu.c
next >
Wrap
C/C++ Source or Header
|
1990-09-29
|
4KB
|
133 lines
/* APPMENU.C: MENUING SKELETON FOR A HYPOTHETICAL APPLICATION */
/* SHOWING CURSOR CONTROL IN MENU SELECTION. */
/* INCLUDES */
#include <stdio.h>
#include <dos.h>
#include <conio.h>
#include "textscrn.h"
#include "popup.h"
/* DEFINES */
#define CR 13
#define F1 59
#define UP 72
#define LEFT 75
#define RITE 77
#define DOWN 80
#ifndef TRUE
#define FALSE 0
#define TRUE !FALSE
#endif
/* LOCAL FUNCTIONS */
void process (POPUP*);
void run (int);
void help (void);
/* MENU TEXT DEFINITION */
char menutext[]= " ** MAIN MENU **\n Accounts payable\n Receivables\n\
Payroll & Personnel\n General ledger\n Quit";
/* POP-UP DEFINITIONS */
POPUP menu = { 4, 31, 9, 50, 2, BLACK, RED, CYAN, BLACK, menutext};
POPUP jobid = {17, 31, 21, 47, 1, RED, 0, GREEN, 0};
POPUP helps = { 7, 34, 13, 76, 1, LTGRAY, 0, MAGENTA, 0};
/*----------------------------------------------------------------*/
main()
{
/* Set up base screen */
_savescrn (0);
_setbordwindow (1, 1, 25, 80, 0, YELLOW, BLACK);
_settextposition (1, 27);
_outtext ("The Empire Corporation, Inc.");
/* Run the program */
popShow (&menu); /* display menu */
process (&menu); /* process choices */
_restscrn (0); /* Clean up and quit */
} /*----------------------------------------------------------*/
void process (POPUP *menu) /* Process main menu choices */
{
int indic = 2, looping = TRUE;
char key;
do {
popHilite (menu, indic); /* hilite indic selection */
key = getch (); /* get a keystroke */
popNormal (menu, indic); /* un-hilite selection */
switch (toupper (key)) { /* act on keystroke */
/* If an alpha selection */
case 'A': run (1); indic = 2; break;
case 'R': run (2); indic = 3; break;
case 'P': run (3); indic = 4; break;
case 'G': run (4); indic = 5; break;
case 'Q': looping = FALSE; break;
/* If user hit Enter on current selection */
case CR : if (indic != 6)
run (indic-1); /* run indic task */
else
looping = FALSE; /* or quit */
break;
/* If user hit a function or cursor key */
case 0 : key = getch (); /* get second byte */
switch (key) { /* act on it */
case F1 : help (); break;
case UP :
case LEFT: if (--indic == 1)
indic = 6; /* wrap down */
popHilite (menu, indic);
break;
case DOWN:
case RITE: popNormal (menu, indic);
if (++indic == 7)
indic = 2; /* wrap up */
popHilite (menu, indic);
break;
} /* end of nested switch */
} /* end of outer switch */
} while (looping);
} /*----------------------------------------------------------*/
void run (int job) /* Simulate running the menu selection */
{
char mssg [20], key;
_savescrn (0); /* save screen */
popShow (&jobid); /* pop up job indent window */
sprintf (mssg, "Running job %d", job);
popCenter (&jobid, 2, mssg); /* identify job number */
popCenter (&jobid, 4, "Press any key...");
key = getch(); /* wait for keypress */
if (key == 0) getch (); /* ignore extended key */
_restscrn (0); /* delete pop-up */
} /*--------------------------------*/
void help (void) /* Pop up help panel if F1 is pressed */
{
char mssg [40], key;
_savescrn (0); /* save screen */
popShow (&helps);
popCenter (&helps, 1, "** H E L P **");
popCenter (&helps, 3, "Select by typing first letter, or");
sprintf (mssg, "Move up with %c or %c, down with %c or %c,",
24, 27, 25, 26);
popCenter (&helps, 4, mssg);
sprintf (mssg, "then press %c%c", 17, 217);
popCenter (&helps, 5, mssg);
popCenter (&helps, 7, "Press any key to resume . . .");
key = getch(); /* wait for keypress */
if (key == 0) getch (); /* ignore extended key */
_restscrn (0); /* restore screen */
} /*--------------------------------*/